﻿// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the 
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

using System;
using System.Windows.Data;
using System.Threading;

namespace TheOliver.Phone.Tools
{
    public class Formatter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            if (parameter != null)   
            {   
                string formatterString = parameter.ToString();   
                if (!string.IsNullOrEmpty(formatterString))   
                {
                    culture = Thread.CurrentThread.CurrentCulture;

                    string result = string.Format(culture, formatterString, value);
                    return result;
                }  
            }  
            
            return value.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
}
